package com.spsoft.vatoutinv.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.spsoft.core.annotation.AnonymousAccess;
import com.spsoft.core.annotation.Log;
import com.spsoft.core.controller.BaseController;
import com.spsoft.core.enums.LogActionType;
import com.spsoft.core.enums.LogMenuEnum;
import com.spsoft.core.model.Result;
import com.spsoft.core.validation.ValidQueryGroup;
import com.spsoft.vatoutinv.model.dto.custom.VmsCustomInfoDto;
import com.spsoft.vatoutinv.model.dto.custom.VmsCustomInfoQueryDto;
import com.spsoft.vatoutinv.model.vo.vmscustom.VmsCustomInfoVO;
import com.spsoft.vatoutinv.service.custom.VmsCustomInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 客户基础信息;SEQ_VMS_CUSTOM_INFO 前端控制器
 * </p>
 *
 * @author dcy
 * @since 2024-01-02
 */
@Api(tags = {"客户基础信息管理"})
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/vmsCustomInfo")
public class VmsCustomInfoController extends BaseController {

    public static final String LOG_MSG = "(客户基础信息控制层)";

    private final VmsCustomInfoService vmsCustomInfoService;

    @ApiOperation("客户基础信息-分页查询")
    @AnonymousAccess(value = "/page", method = RequestMethod.POST, permissionCode = "VMS_CUSTOM")
    @Log(value = "客户基础信息-分页查询", type = LogActionType.SELECT, menuName = LogMenuEnum.DIGITAL_INVOICE_FILE)
    public Result<IPage<VmsCustomInfoVO>> page(@RequestBody VmsCustomInfoQueryDto dto) {
        log.info("{}客户基础信息-分页查询{}", LOG_MSG, JSONObject.toJSONString(dto));
        return vmsCustomInfoService.getPage(dto);
    }

    @ApiOperation("客户基础信息-保存")
    @AnonymousAccess(value = "/saveUpdate", method = RequestMethod.POST, permissionCode = "VMS_FULL_CUSTOM_SAVE")
    @Log(value = "客户基础信息-保存", type = LogActionType.SELECT, menuName = LogMenuEnum.DIGITAL_INVOICE_FILE)
    public Result<Boolean> saveUpdate(@RequestBody @Validated VmsCustomInfoDto dto) {
        if (dto.getId() == null || dto.getId() <= 0) {
            log.info("{}客户基础信息-保存{}", LOG_MSG, JSONObject.toJSONString(dto));
            return vmsCustomInfoService.saveInfo(dto);
        } else {
            log.info("{}客户基础信息-编辑{}", LOG_MSG, JSONObject.toJSONString(dto));
            return vmsCustomInfoService.updateInfo(dto);

        }
    }

    @ApiOperation("客户基础信息-查询详情")
    @AnonymousAccess(value = "/detail", method = RequestMethod.POST, permissionCode = "VMS_CUSTOM")
    @Log(value = "客户基础信息-查询详情", type = LogActionType.SELECT, menuName = LogMenuEnum.DIGITAL_INVOICE_FILE)
    public Result<VmsCustomInfoVO> detail(@RequestBody @Validated(ValidQueryGroup.class) VmsCustomInfoQueryDto dto) {
        log.info("{}客户基础信息-查询详情{}", LOG_MSG, JSONObject.toJSONString(dto));
        return vmsCustomInfoService.detail(dto.getId());
    }

    @ApiOperation("客户基础信息-停用")
    @AnonymousAccess(value = "/disable", method = RequestMethod.POST, permissionCode = "VMS_FULL_CUSTOM_SAVE")
    @Log(value = "客户基础信息-停用", type = LogActionType.SELECT, menuName = LogMenuEnum.DIGITAL_INVOICE_FILE)
    public Result<Boolean> disable(@RequestBody @Validated(ValidQueryGroup.class) VmsCustomInfoQueryDto dto) {
        log.info("{}客户基础信息-停用{}", LOG_MSG, JSONObject.toJSONString(dto));
        return vmsCustomInfoService.disableById(dto.getId());
    }

}